﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Dracham.MapEditor
{
    public partial class frmTextureImporter : Form
    {
        public Color SelectedColor { get; private set; }
        public Boolean UseTransparency { get; private set; }

        public frmTextureImporter(String imagePath)
        {
            InitializeComponent();

            nudRed.ValueChanged += new EventHandler(nud_ValueChanged);
            nudGreen.ValueChanged += new EventHandler(nud_ValueChanged);
            nudBlue.ValueChanged += new EventHandler(nud_ValueChanged);
            pbImage.MouseClick += new MouseEventHandler(pbImage_MouseClick);

            this.pbImage.Image = Bitmap.FromFile(imagePath);
        }

        public void pbImage_MouseClick(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                Color c = (this.pbImage.Image as Bitmap).GetPixel(e.X, e.Y);

                nudRed.Value = c.R;
                nudGreen.Value = c.G;
                nudBlue.Value = c.B;
            }
        }

        private void nud_ValueChanged(object sender, EventArgs e)
        {
            lblColor.BackColor = Color.FromArgb((Int32)nudRed.Value, (Int32)nudGreen.Value, (Int32)nudBlue.Value);
        }

        private void btnOkey_Click(object sender, EventArgs e)
        {
            this.SelectedColor = lblColor.BackColor;
            this.UseTransparency = cbUseTransparency.Checked;

            this.DialogResult = DialogResult.OK;
        }

        private void frmTextureImporter_Load(object sender, EventArgs e)
        {

        }
    }
}
